<?php

namespace App\Http\Resources\Api;

use App\Models\Tenant;
use Illuminate\Http\Resources\Json\JsonResource;
use Illuminate\Support\Str;

class CoachResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param  \Illuminate\Http\Request  $request
     * @return array
     */
    public function toArray($request)
    {
        $tenant = Tenant::find($this->tenant_id);
        $cover_url = config('app.url') . "uploads/{$tenant->admin_prefix}/" . $this->cover_url;
        return [
            'id'=>$this->id,
            'realname' => $this->realname,
            'phone' => $this->phone,
            'gender' => $this->gender,
            'cover_url' => $cover_url,
            'price' => $this->price,
            'sale_num' => $this->sale_num,
            'brief_intro' => $this->brief_intro,
            'brief_intro_ellipsis' => Str::limit($this->brief_intro, 28, '...'),
            'expert' => $this->expert,
            'expert_str' => implode('、', $this->expert),
            'qualification' => $this->qualification,
            'created_at'=>(string)$this->created_at,
            'updated_at'=>(string)$this->updated_at
        ];
    }
}
